package com.harry.rabbitmqhello;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Harry
 * @date 2018/3/30 14:52
 */
@Configuration
public class RabbitConfig {

    final static String message = "topic.message";
    final static String messages = "topic.messages";
    final static String queue_name_was = "topic.queue_name_was";
    final static String qnw = "topic.qnw";

    @Bean(name = "qnw")
    public Queue queueQnw(){
        return new Queue(RabbitConfig.qnw);
    }

    @Bean(name = "queue_name_was")
    public Queue queueWas(){
        return new Queue(RabbitConfig.queue_name_was);
    }

    @Bean(name = "message")
    public Queue queueMessage() {
        return new Queue(RabbitConfig.message);
    }

    @Bean(name = "messages")
    public Queue queueMessages() {
        return new Queue(RabbitConfig.messages);
    }

    @Bean
    TopicExchange exchange() {
        return new TopicExchange("exchange");
    }

    @Bean
    Binding bindingExchangeQnw(@Qualifier("qnw")Queue queueMessage, TopicExchange exchange) {
        return BindingBuilder.bind(queueMessage).to(exchange).with(qnw);
    }

    @Bean
    Binding bindingExchangeWas(@Qualifier("queue_name_was") Queue queueMessage, TopicExchange exchange) {
        return BindingBuilder.bind(queueMessage).to(exchange).with(queue_name_was);
    }

    @Bean
    Binding bindingExchangeMessage(@Qualifier("message") Queue queueMessage, TopicExchange exchange) {
        return BindingBuilder.bind(queueMessage).to(exchange).with(message);
    }

    @Bean
    Binding bindingExchangeMessages(@Qualifier("messages") Queue queueMessages, TopicExchange exchange) {
        return BindingBuilder.bind(queueMessages).to(exchange).with("topic.#");
    }

}
